package tcp;

import java.io.*;
import java.net.*;
import java.util.Scanner;

public class SockClient {
    public static void main(String[] args) {
        try {
            Socket sock = new Socket("192.168.56.1", 3333);
            sock.setSoTimeout(2 * 1000);
            if (sock.isConnected()) System.out.println("我成功的连接上了");

//            PrintWriter bfWriter = new
//                    PrintWriter(sock.getOutputStream(), true);

            PrintWriter bfWriter = new
                                    PrintWriter(new BufferedWriter(new OutputStreamWriter(sock.getOutputStream())), true);BufferedReader bfReader = new BufferedReader(new InputStreamReader(sock.getInputStream()));
            Scanner sc = new Scanner(System.in);
            String temp = sc.nextLine();

            System.out.println("开始发送数据");
            bfWriter.println("1234\n");
            System.out.println("数据发送完成");


            System.out.println("应答为" + bfReader.readLine());
            System.out.println("应答输出完成");

            bfReader.close();
            bfWriter.close();
            sock.close();
        } catch (IOException ioe) {
            ioe.printStackTrace();
        }
    }
}

